﻿using System;
using System.Collections.Generic;
using Model_SSResourceManager;

namespace Presenter_SSResourceManager
{
    public class PresenterResourceView
    {
        private readonly ModelsManager _mModel;
        private readonly IViewResource _viewResource;

        public PresenterResourceView(IViewResource view)
        {
            this._viewResource = view;
            _mModel = ModelInstanse.Get();
        }

        public string GetLogin(Object userId)
        {
            return _mModel.userModel.Get(Guid.Parse(userId.ToString())).Login;
        }

        public void Refresh(Guid resourceId)
        {
            _viewResource.ShowResourceInfo(GetResource(resourceId), GetQueues(resourceId));
        }

        private IEnumerable<Queue> GetQueues(Guid resourceId)
        {
            return _mModel.queueModel.GetAllForResource(resourceId);
        }

        private Resource GetResource(Guid resourceId)
        {
            return _mModel.resourceModel.Get(resourceId);
        }

        public void BookForNearTime(Guid resourceId, Guid userId)
        {
            _viewResource.ShowBookingResult(_mModel.queueModel.CreateNearBook(resourceId, userId));
        }

    }
}
